package com.alex.space.commons.date.expression;

import java.util.Arrays;
import java.util.List;

/**
 * @author Alex
 *         Created by Alex on 2017/12/21.
 */
public class ExpressionTest {

    public static void main(String[] args) {

        try {

            List<String> asList = Arrays.asList(
                    "2017-06-06|1y",
                    "2017-06-06|1m",
                    "2017-06-06|1d",
                    "2017-06-06|1q",
                    "2017-06-06|1w",
                    "2017-06-06|2y",
                    "2017-06-06|2m",
                    "2017-06-06|2d",
                    "2017-06-06|2q",
                    "2017-06-06|2w",
                    "2017-06-06/1y",
                    "2017-06-06/1m",
                    "2017-06-06/1d",
                    "2017-06-06/1q",
                    "2017-06-06/1w",
                    "2017-06-06/2y",
                    "2017-06-06/2m",
                    "2017-06-06/2d",
                    "2017-06-06/2q",
                    "2017-06-06/2w");

            asList.forEach(ExpressionTest::transfer);

        } catch (

                Exception e) {
            e.printStackTrace();
        }
    }

    private static DateModel transfer(String expression) {
        RelativeExpression relative = new RelativeExpression();
        AbsoluteExpression absolute = new AbsoluteExpression();
        DateModel result = new DateModel();

        if (relative.match(expression)) {
            result = relative.express(expression);
            System.out.println(expression + ": " + result.toString());
        } else if (absolute.match(expression)) {
            result = absolute.express(expression);
            System.out.println(expression + ": " + result.toString());
        } else {
            System.out.println("格式不正确");
        }
        return result;
    }
}
